﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using TalentPools.Model;

namespace TalentPools.DAL
{
    public class invite_infoService
    {
        #region 添加招聘信息
        /// <summary>
        /// 添加招聘信息
        /// </summary>
        /// <param name="invite"></param>
        /// <returns></returns>
        public bool InsertInvite(invite_info invite)
        {
            string sql = "insert into invite_info(Zpzw,Zpczw,Zptype,Zpsex,Zprs,Zpminyear,Zpmaxyear,Zpworkyear,Zpzz,Zphk,Zpwp,Zpmoney,Zpdes,Zplxr,Zpmobile,Zpemail,Zpadd,CompanyName)values(@Zpzw,@Zpczw,@Zptype,@Zpsex,@Zprs,@Zpminyear,@Zpmaxyear,@Zpworkyear,@Zpzz,@Zphk,@Zpwp,@Zpmoney,@Zpdes,@Zplxr,@Zpmobile,@Zpemail,@Zpadd,@CompanyId)";
            SqlParameter[] paras = new SqlParameter[] { 
            new SqlParameter("@Zpzw",invite.Zpzw),
            new SqlParameter("@Zpczw",invite.Zpczw),
            new SqlParameter("@Zptype",invite.Zptype),
            new SqlParameter("@Zpsex",invite.Zpsex),
            new SqlParameter("@Zprs",invite.Zprs),
            new SqlParameter("@Zpminyear",invite.Zpminyear),
            new SqlParameter("@Zpmaxyear",invite.Zpmaxyear),
            new SqlParameter("@Zpworkyear",invite.Zpworkyear),
            new SqlParameter("@Zpzz",invite.Zpzz),
            new SqlParameter("@Zphk",invite.Zphk),
            new SqlParameter("@Zpwp",invite.Zpwp),
            new SqlParameter("@Zpmoney",invite.Zpmoney),
            new SqlParameter("@Zpdes",invite.Zpdes),
            new SqlParameter("@Zplxr",invite.Zplxr),
            new SqlParameter("@Zpmobile",invite.Zpmobile),
            new SqlParameter("@Zpemail",invite.Zpemail),
            new SqlParameter("@Zpadd",invite.Zpadd),
            new SqlParameter("@CompanyId",invite.CompanyName)
            };
            return DBHelper.ExecuteNonQuery(CommandType.Text, sql, paras) > 0;
        }

        #endregion

        #region 修改招聘信息
        /// <summary>
        /// 修改招聘信息
        /// </summary>
        /// <param name="invite"></param>
        /// <returns></returns>
        public bool UpdateInvite(invite_info invite)
        {
            string sql = "Update invite_info set Zpzw=@Zpzw,Zpczw=@Zpczw,Zptype=@Zptype,Zpsex=@Zpsex,Zprs=@Zprs,Zpminyear=@Zpminyear,Zpmaxyear=@Zpmaxyear,Zpworkyear=@Zpworkyear,Zpzz=@Zpzz,Zphk=@Zphk,Zpwp=@Zpwp,Zpmoney=@Zpmoney,Zpdes=@Zpdes,Zplxr=@Zplxr,Zpmobile=@Zpmobile,Zpemail=@Zpemail,Zpadd=@Zpadd where CompanyName=@CompanyId";
            SqlParameter[] paras = new SqlParameter[] { 
             new SqlParameter("@Zpzw",invite.Zpzw),
            new SqlParameter("@Zpczw",invite.Zpczw),
            new SqlParameter("@Zptype",invite.Zptype),
            new SqlParameter("@Zpsex",invite.Zpsex),
            new SqlParameter("@Zprs",invite.Zprs),
            new SqlParameter("@Zpminyear",invite.Zpminyear),
            new SqlParameter("@Zpmaxyear",invite.Zpmaxyear),
            new SqlParameter("@Zpworkyear",invite.Zpworkyear),
            new SqlParameter("@Zpzz",invite.Zpzz),
            new SqlParameter("@Zphk",invite.Zphk),
            new SqlParameter("@Zpwp",invite.Zpwp),
            new SqlParameter("@Zpmoney",invite.Zpmoney),
            new SqlParameter("@Zpdes",invite.Zpdes),
            new SqlParameter("@Zplxr",invite.Zplxr),
            new SqlParameter("@Zpmobile",invite.Zpmobile),
            new SqlParameter("@Zpemail",invite.Zpemail),
            new SqlParameter("@Zpadd",invite.Zpadd),
            new SqlParameter("@CompanyId",invite.CompanyName)
            };
            return DBHelper.ExecuteNonQuery(CommandType.Text, sql, paras) > 0;
        }

        #endregion

        #region 获取招聘信息
        /// <summary>
        /// 获取招聘信息
        /// </summary>
        /// <param name="companyname"></param>
        /// <returns></returns>
        public DataSet GetInviteDS(string companyname)
        {
            string sql = "select * from invite_info where CompanyName='" + companyname + "'";
            using (DataSet ds = DBHelper.ExecuteDataSet(CommandType.Text, sql, null))
            {
                return ds;
            }
        }
        /// <summary>
        /// 获取招聘信息
        /// </summary>
        /// <param name="companyname"></param>
        /// <returns></returns>
        public List<invite_info> GetInviteList(string companyname)
        {
            string sql = "select * from invite_info where CompanyName='"+companyname+"'";
            List<invite_info> list = new List<invite_info>();
            using (SqlDataReader dr=DBHelper.ExecuteGetReader(CommandType.Text,sql,null))
            {
                while (dr.Read())
                {
                    invite_info invite = new invite_info();
                    invite.Zpadd = dr["Zpadd"].ToString();
                    invite.Zpemail = dr["Zpemail"].ToString();
                    invite.Zpmobile = dr["Zpmobile"].ToString();
                    invite.Zplxr = dr["Zplxr"].ToString();
                    invite.Zpdes = dr["Zpdes"].ToString();
                    invite.Zpmoney = dr["Zpmoney"].ToString();
                    invite.Zpwp = dr["Zpwp"].ToString();
                    invite.Zphk = dr["Zphk"].ToString();
                    invite.Zpzz = dr["Zpzz"].ToString();
                    invite.Zpworkyear = dr["Zpworkyear"].ToString();
                    invite.Zpmaxyear = dr["Zpmaxyear"].ToString();
                    invite.Zpminyear = dr["Zpminyear"].ToString();
                    invite.Zprs = Convert.ToInt32(dr["Zprs"]);
                    invite.Zpsex = dr["Zpsex"].ToString();
                    invite.Zptype = dr["Zptype"].ToString();
                    invite.Zpczw = dr["Zpczw"].ToString();
                    invite.Zpzw = dr["Zpzw"].ToString();
                    invite.Id = Convert.ToInt32(dr["Id"]);
                    list.Add(invite);
                }
                return list;
            }
        }
        /// <summary>
        /// 获取招聘信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public invite_info GetInviteObj(int id)
        {
            string sql = "select top 1 * from invite_info where id=@id";
            SqlParameter para = new SqlParameter("@id", id);
            using (SqlDataReader dr=DBHelper.ExecuteGetReader(CommandType.Text,sql,para))
            {
                if (dr.Read())
                {
                    invite_info invite = new invite_info();
                    invite.Zpadd = dr["Zpadd"].ToString();
                    invite.Zpemail = dr["Zpemail"].ToString();
                    invite.Zpmobile = dr["Zpmobile"].ToString();
                    invite.Zplxr = dr["Zplxr"].ToString();
                    invite.Zpdes = dr["Zpdes"].ToString();
                    invite.Zpmoney = dr["Zpmoney"].ToString();
                    invite.Zpwp = dr["Zpwp"].ToString();
                    invite.Zphk = dr["Zphk"].ToString();
                    invite.Zpzz = dr["Zpzz"].ToString();
                    invite.Zpworkyear = dr["Zpworkyear"].ToString();
                    invite.Zpmaxyear = dr["Zpmaxyear"].ToString();
                    invite.Zpminyear = dr["Zpminyear"].ToString();
                    invite.Zprs = Convert.ToInt32(dr["Zprs"]);
                    invite.Zpsex = dr["Zpsex"].ToString();
                    invite.Zptype = dr["Zptype"].ToString();
                    invite.Zpczw = dr["Zpczw"].ToString();
                    invite.Zpzw = dr["Zpzw"].ToString();
                    return invite;
                }
                return null;
            }
        }
        #endregion

        #region 删除招聘信息
        /// <summary>
        /// 删除招聘信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteInvite(int id)
        {
            string sql = "delete from invite_info where id=@id";
            SqlParameter para = new SqlParameter("@id", id);
            return DBHelper.ExecuteNonQuery(CommandType.Text, sql, para) > 0;
        }
        #endregion
    }
}
